package com.chen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.entity.Classify;
import com.chen.mapper.ClassifyMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chen.common.Result;
import com.chen.service.IContentsService;
import com.chen.entity.Contents;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Y·C
 * @since 2023-04-23
 */
@Api(tags = "学堂内容")
@RestController
@RequestMapping("/contents")
public class ContentsController {

    @Resource
    private IContentsService contentsService;

    @Resource
    private ClassifyMapper classifyMapper;

    @ApiOperation("添加学堂内容或修改")
    @PostMapping
    public Result save(@RequestBody Contents contents) {
        contentsService.saveOrUpdate(contents);
        return Result.success();
    }


    @ApiOperation("批量删除学堂内容")
    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        contentsService.removeByIds(ids);
        return Result.success();
    }

    @ApiOperation("查询所有学堂内容")
    @GetMapping
    public Result findAll() {


        return Result.success(contentsService.getList());
    }


//    @ApiOperation("分页显示全部")
//    @GetMapping("/page")
//    public Result findPage(@RequestParam Integer pageNum,
//                           @RequestParam Integer pageSize,
//                           @RequestParam(defaultValue = "") String title,
//                           @RequestParam(defaultValue = "") Integer mid) {
//        QueryWrapper<Contents> queryWrapper = new QueryWrapper<>();
//        queryWrapper.orderByDesc("id");
//        queryWrapper.like("title",title);
//        queryWrapper.eq("mid",mid);
//
//        return Result.success(contentsService.page(new Page<>(pageNum, pageSize), queryWrapper));
//    }
//





}

